interface EnvIn {
    [key: string]: string;
}

let isInit = true;

export default function getUrl(url: string) {
    let URL = url;

    // #ifdef MP-WEIXIN
    // 体验版小程序
    let testEnv = false
    try {
        // __wxConfig.envVersion
        const accountInfo = wx.getAccountInfoSync();
        // console.log('accountInfo', accountInfo);
        testEnv = accountInfo?.miniProgram.envVersion === 'trial'
    } catch (err) {
        console.log(err.message);
    }
    const envJson: EnvIn = {
        // https://test.51zidan.com/testnewcrm
        // development: 'http://192.168.1.151:8188',
        // development: 'http://192.168.1.108:8188',
        // development: 'http://192.168.1.230:8188',
        // development: 'http://192.168.1.222:8188',
        // development: 'http://192.168.1.133:8188',
        development: 'https://test.51zidan.com/testnewcrm',
        test: 'https://test.51zidan.com/testnewcrm',
        uat: 'https://test.51zidan.com/testcrm',
        production: 'https://test.51zidan.com/testcrm',
    }
    /* eslint-disable-next-line */
    const type = testEnv ? 'test' : ((getApp as any)().globalData.envType || process.env.NODE_ENV);

    const baseUrl = envJson[type];
    isInit = false;
    URL = baseUrl + URL;
    // #endif
    return URL;
}